package com.mkx.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "redis.lock")
public class RedisLockProperties {
    
    private boolean enabled = true;
    private String prefix = "lock:";
    private long expireTime = 30000;
    private long waitTime = 5000;
    private long retryInterval = 100;
    private boolean adaptiveRetryEnabled = true;
    private boolean watchDogEnabled = true;
    private long watchDogInterval = 10000;
    
    // 机器学习预测配置
    private boolean mlPredictionEnabled = true;
    private int mlHistoryWindowSize = 100;
    private double mlExponentialSmoothingAlpha = 0.3;
    private double mlSeasonalWeight = 0.2;
    
    // WatchDog 策略配置
    private WatchDogStrategy watchDogStrategy = WatchDogStrategy.THREAD_POOL;
    private TimeWheelConfig timeWheel = new TimeWheelConfig();
    
    // 自动配置优化
    private boolean autoConfigOptimizationEnabled = true;
    private long autoConfigCheckInterval = 30000; // 30秒
    private double highLoadCpuThreshold = 0.8;
    private double highLoadMemoryThreshold = 0.85;
    
    // WatchDog 策略枚举
    public enum WatchDogStrategy {
        THREAD_POOL,    // 传统线程池方式
        TIME_WHEEL      // 时间轮方式
    }
    
    // 时间轮配置
    public static class TimeWheelConfig {
        private long tickDuration = 100; // 每个tick的持续时间(ms)
        private int ticksPerWheel = 512; // 时间轮大小
        
        public long getTickDuration() { return tickDuration; }
        public void setTickDuration(long tickDuration) { this.tickDuration = tickDuration; }
        
        public int getTicksPerWheel() { return ticksPerWheel; }
        public void setTicksPerWheel(int ticksPerWheel) { this.ticksPerWheel = ticksPerWheel; }
    }
    
    // Getters and Setters
    public boolean isEnabled() { return enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
    
    public String getPrefix() { return prefix; }
    public void setPrefix(String prefix) { this.prefix = prefix; }
    
    public long getExpireTime() { return expireTime; }
    public void setExpireTime(long expireTime) { this.expireTime = expireTime; }
    
    public long getWaitTime() { return waitTime; }
    public void setWaitTime(long waitTime) { this.waitTime = waitTime; }
    
    public long getRetryInterval() { return retryInterval; }
    public void setRetryInterval(long retryInterval) { this.retryInterval = retryInterval; }

    public boolean isAdaptiveRetryEnabled() { return adaptiveRetryEnabled; }
    public void setAdaptiveRetryEnabled(boolean adaptiveRetryEnabled) { this.adaptiveRetryEnabled = adaptiveRetryEnabled; }
    
    public boolean isMlPredictionEnabled() { return mlPredictionEnabled; }
    public void setMlPredictionEnabled(boolean mlPredictionEnabled) { this.mlPredictionEnabled = mlPredictionEnabled; }
    
    public int getMlHistoryWindowSize() { return mlHistoryWindowSize; }
    public void setMlHistoryWindowSize(int mlHistoryWindowSize) { this.mlHistoryWindowSize = mlHistoryWindowSize; }
    
    public double getMlExponentialSmoothingAlpha() { return mlExponentialSmoothingAlpha; }
    public void setMlExponentialSmoothingAlpha(double mlExponentialSmoothingAlpha) { this.mlExponentialSmoothingAlpha = mlExponentialSmoothingAlpha; }
    
    public double getMlSeasonalWeight() { return mlSeasonalWeight; }
    public void setMlSeasonalWeight(double mlSeasonalWeight) { this.mlSeasonalWeight = mlSeasonalWeight; }
    
    public boolean isAutoConfigOptimizationEnabled() { return autoConfigOptimizationEnabled; }
    public void setAutoConfigOptimizationEnabled(boolean autoConfigOptimizationEnabled) { this.autoConfigOptimizationEnabled = autoConfigOptimizationEnabled; }
    
    public long getAutoConfigCheckInterval() { return autoConfigCheckInterval; }
    public void setAutoConfigCheckInterval(long autoConfigCheckInterval) { this.autoConfigCheckInterval = autoConfigCheckInterval; }
    
    public double getHighLoadCpuThreshold() { return highLoadCpuThreshold; }
    public void setHighLoadCpuThreshold(double highLoadCpuThreshold) { this.highLoadCpuThreshold = highLoadCpuThreshold; }
    
    public double getHighLoadMemoryThreshold() { return highLoadMemoryThreshold; }
    public void setHighLoadMemoryThreshold(double highLoadMemoryThreshold) { this.highLoadMemoryThreshold = highLoadMemoryThreshold; }

    public boolean isWatchDogEnabled() { return watchDogEnabled; }
    public void setWatchDogEnabled(boolean watchDogEnabled) { this.watchDogEnabled = watchDogEnabled; }
    
    public long getWatchDogInterval() { return watchDogInterval; }
    public void setWatchDogInterval(long watchDogInterval) { this.watchDogInterval = watchDogInterval; }
    
    public WatchDogStrategy getWatchDogStrategy() { return watchDogStrategy; }
    public void setWatchDogStrategy(WatchDogStrategy watchDogStrategy) { this.watchDogStrategy = watchDogStrategy; }
    
    public TimeWheelConfig getTimeWheel() { return timeWheel; }
    public void setTimeWheel(TimeWheelConfig timeWheel) { this.timeWheel = timeWheel; }
}